import { DOUBLE_STATUS } from '@/enum/common';
import { GET, POST } from '@/libs';

type PageResponse<List = any> = {
  current: number;
  size: number;
  total: number;
  list: Array<List>;
};

export type DictionaryWords = {
  id: number;

  /**
   * 词典id
   */
  dictionaryId: number;

  /**
   * 单词内容
   */
  wordContent: string;

  /**
   * 单词发音
   */
  wordPronunciation: string;

  /**
   * 翻译
   */
  wordTranslate: string;

  /**
   * 收藏状态
   */
  collectionStatus: DOUBLE_STATUS;
};
// /dictionary/getDictionaryWords?dictionaryId=1&current=1&size=10
export const getDictionaryWords = (dictionaryId = 0, current = 1, size = 1) => {
  return GET<PageResponse<DictionaryWords>>({
    url: '/dictionary/getDictionaryWords',
    params: {
      dictionaryId,
      current,
      size
    }
  });
};

export type anserDto = {
  /**
   * 已学习单词的id
   */
  wordId: number;

  /**
   * 词典id
   */

  dictionaryId: number;

  answer: string;
};

export const answerMannyProblem = (data: anserDto) => {
  return POST({
    url: '/dictionary/answerMannyProblem',
    data: [data]
  });
};

type RandDataDto = {
  limit: number;
  id: number;
};

export const getRanDataLimit = (data: RandDataDto) => {
  return POST<DictionaryWords[]>({
    url: '/dictionary/getRanDataLimit',
    data: data
  });
};

export type AnserOneDto = {
  /**
   * 已学习单词的id
   */

  wordId: number;

  /**
   * 词典id
   */

  dictionaryId: number;

  answer: string;
};

export const answerOneProblem = (data: AnserOneDto) => {
  return POST({
    url: '/dictionary/answerOneProblem',
    data
  });
};

type CollectionWordDto = {
  wordId: number;
  dictionaryId: number;
};

type CollectionWord = {
  id: number;

  wordId: number;

  userId: number;

  dictionaryId: number;

  status: DOUBLE_STATUS;
};

export const collectionWord = (data: CollectionWordDto) => {
  return POST<CollectionWord>({
    url: '/dictionary/collectionWord',
    data
  });
};

// /dictionary/getDictionaryList
export type Dictionary = {
  id: number;

  dictionaryName: string;
};

export const getDictionaryList = () => {
  return GET<Dictionary[]>({
    url: '/dictionary/getDictionaryList'
  });
};

// /dictionary/getMyCollectionWords
export type CollectionWordListItem = CollectionWord & {
  wordInfo: DictionaryWords;
};

export const getMyCollectionWords = () => {
  return GET<CollectionWordListItem[]>({
    url: '/dictionary/getMyCollectionWords'
  });
};

export type DictionaryStudyRecord = {
  id: number;

  wordId: number;

  userId: number;

  dictionaryId: number;

  /**
   * 单词详情
   */
  wordInfo: DictionaryWords;
};

export const getMyStudyWordsHistory = () => {
  return GET<DictionaryStudyRecord[]>({
    url: '/dictionary/getMyStudyWordsHistory'
  });
};

// /dictionary/getDetail

export const getDetail = (id: number) => {
  return GET<DictionaryWords>({
    url: '/dictionary/getDetail',
    params: {
      id
    }
  });
};

export type DictionaryStudyRecordError = {
  id: number;

  wordId: number;

  userId: number;

  dictionaryId: number;

  answerError: string;

  answer: string;

  status: DOUBLE_STATUS;

  /**
   * 单词详情
   */
  wordInfo: DictionaryWords;
};

export const getMyErrorWords = () => {
  return GET<DictionaryStudyRecordError[]>({
    url: '/dictionary/getMyErrorWords'
  });
};
